<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <img src="images/z.gif" alt="">
    <p>早上好</p>
    <script>
        var img = document.querySelector('img');
        var p = document.querySelector('p');
        var date = new Date();
        var h = date.getHours();
        if (h < 12) {
            img.src = "images/z.gif";
            p.innerHTML = "早上好";
        } else if (h < 18) {
            img.src = "images/x.gif";
            p.innerHTML = "下午好";
        } else {
            img.src = "images/w.gif";
            p.innerHTML = "晚上好";

        }
    </script>
</body>

</html>